IF exists(SELECT * FROM dbo.sysobjects WHERE name='maakKalender' AND xtype='P') 
BEGIN
	DROP PROCEDURE maakKalender
END
GO

create procedure maakKalender @beginDatum as varchar(10)
as
  set dateformat dmy
  set nocount on
  declare @teller As Int
  declare @datum As Datetime
  declare @voormiddag as char(1)
  declare @namiddag as char(1)
  declare @dag as int
  declare @maand as int
  set @datum = convert(dateTime,@begindatum)
  delete from kalender
  set @teller=1
  while @teller < 367
    begin
      set @dag = datepart(weekday,@datum)
      set @maand = datepart(month,@datum)
      set @voormiddag = ''		
      set @namiddag = ''	
      if (@maand=7) or (@maand=8)
 	begin
	  set @voormiddag = 'X'
	  set @namiddag = 'X'
	end
      else
   	begin
          if(@dag = 1) or (@dag=7)
		begin
		  set @voormiddag = 'X'
	  	  set @namiddag = 'X'
		end
	  if (@dag = 4)
		begin
		  set @voormiddag = ''
	  	  set @namiddag = 'X'
		end	
	end
      insert kalender(datum,voormiddag,namiddag)
		values(@datum,@voormiddag,@namiddag)
      set @datum = dateAdd(day,1,@datum)
      set @teller = @teller + 1
  end
  